---
title: 'clear | Cypress Documentation'
description: Clear the value of an input or textarea in Cypress.
sidebar_label: clear
slug: /api/commands/clear
---

<ProductHeading product="app" />

# clear

Clear the value of an `input` or `textarea`.

It is [unsafe](/app/core-concepts/retry-ability#Only-queries-are-retried) to
chain further commands that rely on the subject after `.clear()`.

:::info

An alias for [`.type('{selectall}{del}')`](/api/commands/type)

:::

## Syntax

```javascript
.clear()
.clear(options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.get('[type="text"]').clear() // Clear text input
cy.get('textarea').type('Hi!')
cy.get('textarea').clear() // Clear textarea
cy.focused().clear() // Clear focused input/textarea
```

<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage**

```javascript
cy.clear() // Errors, cannot be chained off 'cy'
cy.get('nav').clear() // Errors, 'get' doesn't yield input or textarea
cy.clock().clear() // Errors, 'clock' does not yield DOM elements
```

### Arguments

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `.clear()`.

| Option                       | Default                                                                     | Description                                                                                                                                     |
| ---------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `animationDistanceThreshold` | [`animationDistanceThreshold`](/app/references/configuration#Actionability) | The distance in pixels an element must exceed over time to be [considered animating](/app/core-concepts/interacting-with-elements#Animations).  |
| `force`                      | `false`                                                                     | Forces the action, disables [waiting for actionability](#Assertions)                                                                            |
| `log`                        | `true`                                                                      | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log)                                                             |
| `scrollBehavior`             | [`scrollBehavior`](/app/references/configuration#Actionability)             | Viewport position to where an element [should be scrolled](/app/core-concepts/interacting-with-elements#Scrolling) before executing the command |
| `timeout`                    | [`defaultCommandTimeout`](/app/references/configuration#Timeouts)           | Time to wait for `.clear()` to resolve before [timing out](#Timeouts)                                                                           |
| `waitForAnimations`          | [`waitForAnimations`](/app/references/configuration#Actionability)          | Whether to wait for elements to [finish animating](/app/core-concepts/interacting-with-elements#Animations) before executing the command.       |

<HeaderYields />

- `.clear()` yields the same subject it was given.
- It is [unsafe](/app/core-concepts/retry-ability#Only-queries-are-retried)
  to chain further commands that rely on the subject after `.clear()`.

## Examples

### No Args

#### Clear the input and type a new value

```javascript
cy.get('textarea').clear()
cy.get('textarea').type('Hello, World')
```

## Notes

### Actionability

#### The element must first reach actionability

`.clear()` is an "action command" that follows all the rules of
[Actionability](/app/core-concepts/interacting-with-elements).

### Documentation

`.clear()` is an alias for
[`.type({selectall}{del})`](/api/commands/type).

Please read the [`.type()`](/api/commands/type) documentation for more details.

## Rules

<HeaderRequirements />

- `.clear()` requires being chained off a command that yields DOM element(s).
- `.clear()` requires the element to be an `input` or `textarea`.

<HeaderAssertions />

- `.clear()` will automatically wait for the element to reach an
  [actionable state](/app/core-concepts/interacting-with-elements)
- `.clear()` will automatically [retry](/app/core-concepts/retry-ability)
  until all chained assertions have passed

<HeaderTimeouts />

- `.clear()` can time out waiting for the element to reach an
  [actionable state](/app/core-concepts/interacting-with-elements).
- `.clear()` can time out waiting for assertions you've added to pass.

## Command Log

**_Clear the input and type a new value_**

```javascript
cy.get('input[name="name"]').clear()
cy.get('input[name="name"]').type('Jane Lane')
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/clear/clear-input-in-cypress.png"
  alt="Command log for clear"
/>

When clicking on `clear` within the command log, the console outputs the
following:

<DocsImage
  src="/img/api/clear/one-input-cleared-in-tests.png"
  alt="console.log for clear"
/>

## See also

- [`.blur()`](/api/commands/blur)
- [`.focus()`](/api/commands/focus)
- [`.type()`](/api/commands/type)
